<%@ page import="java.util.List" %>
<%@ page import="com.my.entity.User" %><%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2021/8/1
  Time: 20:45
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <script type="text/javascript" src="/js/jquery-3.4.1.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){
            $("tr:odd").css("background-color","yellow");
        });
    </script>
    <title>Users列表</title>
</head>
<body>
    <%
        String error = (String) request.getAttribute("error");
        if(error==null){
            error="start";
        }
        switch (error){
            case "start":
                break;
            case "AddNoError":
                %>
                    <script type="text/javascript" language="javascript">
                        alert("添加成功！");
                    </script>
                <%
                break;
            case "AddError":
                %>
                    <script type="text/javascript" language="javascript">
                        alert("添加失败！");
                    </script>
                <%
                break;
            case "DeleteNoError":
                %>
                    <script type="text/javascript" language="javascript">
                        alert("删除成功！");
                    </script>
                <%
                break;
            case "DeleteError":
                %>
                    <script type="text/javascript" language="javascript">
                        alert("删除失败！");
                    </script>
                <%
                break;
            case "UpdateNoError":
                %>
                    <script type="text/javascript" language="javascript">
                        alert("修改密码成功！");
                    </script>
                <%
                break;
            case "UpdateError":
                %>
                    <script type="text/javascript" language="javascript">
                        alert("用户名或密码错误！");
                    </script>
                <%
                break;
        }
    %>


    <table border="1px">
        <tr>
          <th>用户名</th>
          <th>操作</th>
        </tr>
        <%
            List<User> users = (List<User>) request.getAttribute("Users");
            for(User user: users){
        %>
            <tr>
                <td><a href="QueryOneUserServlet?uname=<%=user.getName()%>"><%=user.getName()%></a></td>
                <td><a href="DeleteUserServlet?uname=<%=user.getName()%>">删除</a></td>
            </tr>
        <%
            }
        %>
    </table>
    <br/>
    <a href="AddUser.jsp">添加用户信息</a><br/>
    <a href="deleteUser.jsp">删除用户信息</a><br/>
    <a href="updateUser.jsp">更新用户密码</a><br/>
</body>
</html>
